package com.ssm.controller;

import com.ssm.domain.Permission;
import com.ssm.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;
    @GetMapping("/findAll")
    public ModelAndView findAll(){
        ModelAndView mv = new ModelAndView();
       List<Permission> list =  permissionService.findAll();
        mv.addObject("permissionList", list);
        mv.setViewName("permission-list");
        return mv;
    }

    @PostMapping("/save")
    public String save(Permission permission) {
        permissionService.save(permission);
        return "redirect:findAll";
    }


}
